<?php

/**
 * event actions.
 *
 * @package    cpfaizenay
 * @subpackage event
 * @author     Manu
 * @version    1.0
 */
class eventActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request) {
      $slug = $request->getParameter('title_slug');
      $this->currentEvent = Doctrine::getTable('Event')->getCurrentEvent($slug)->fetchOne();
      $this->forward404Unless($this->currentEvent);

      isicsBreadcrumbs::getInstance()->addItem($this->currentEvent->getTitle(), '#');

      $response = $this->getResponse();
      Utils::setSlogTitle($this->currentEvent['title'], $response);
      $response->addMeta('description', Utils::slugDescription($this->currentEvent['text']));

      // facebook meta
      $response->addMeta('og:title', $this->currentEvent['title']);
      $response->addMeta('og:type', 'article');
      $response->addMeta('og:description', Utils::slugDescription($this->currentEvent['text']));
      if($this->currentEvent['sfAsset'][ 'filename' ]){
        $response->addMeta('og:image', sfConfig::get('app_homePage_uri') . "/" . $this->currentEvent['sfAsset'][ 'Folder' ][ 'relative_path' ] . "/thumbnail/small_" . $this->currentEvent['sfAsset'][ 'filename' ]);
      }
  }

  public function executeAllEvents(sfWebRequest $request) {
      $this->pager = new sfDoctrinePager(
        'Event',
        sfConfig::get('app_news_max_all_events', 15)
      );
      $this->pager->setQuery(Doctrine::getTable('Event')->getEvents(sfConfig::get('app_news_max_all_events', 15), false));
      $this->pager->setPage($request->getParameter('page', 1));
      $this->pager->init();
      $this->events_list = $this->pager;

      isicsBreadcrumbs::getInstance()->addItem('Evénements/Infos de CPF Aizenay', '#');

      $response = $this->getResponse();
      Utils::setSlogTitle('Evénements/Infos de CPF Aizenay', $response);
  }

}